package main

import (
	"fmt"
	"log"
	"net"
	"os/exec"
)

func main() {
	// shell udp reverse proxy
	addr := &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 9981}
	listener, err := net.ListenUDP("udp", addr)
	if err != nil {
		log.Fatalln(err)
	}
	data := make([]byte, 1024)
	n, remoteAddr, err := listener.ReadFromUDP(data)
	if err != nil {
		log.Fatalln(err)
	}
	result := string(data[:n])

	var echo []byte
	if echo, err = exec.Command("./echo.sh", result).Output(); err != nil {
		log.Fatalln(err)
	}
	fmt.Println(string(echo))
	_, err = listener.WriteToUDP(echo, remoteAddr)
}
